package com.example.wwk.graduationpractice.NetDataUtils;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.example.wwk.graduationpractice.Bean.AlreadyUserBean;
import com.example.wwk.graduationpractice.Bean.QuestionBean;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.util.List;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by wwk on 2017/4/21.
 * 注册或登陆用户时，查询该用户组是否有这个用户
 */

public class GroupUtils {

    public static AlreadyUserBean getAlreadyUser(String userName, String groupName) {
        String Url = "http://192.168.191.1:9090/plugins/register/getregister?action=alreadyuser";
        Url += "&groupName=" + groupName + "&username=" + userName;
        final String finalUrl = Url;
        AlreadyUserBean alreadyUserBean;
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(finalUrl)
                .build();
        try {
            Response response = client.newCall(request).execute();
            String responseData = response.body().string();
            Log.d("123", "getAlreadyUser run: " + responseData);
            Gson gson = new Gson();
            alreadyUserBean = gson.fromJson(responseData, new TypeToken<AlreadyUserBean>() {
            }.getType());
            return alreadyUserBean;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }


    }
}
